package com.spzx.product.api.factory;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteProductSkuService;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.dto.IndexHotData;
import com.spzx.product.api.domain.dto.ProductSkuDTO;
import com.spzx.product.api.domain.dto.SkuSearchDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductSkuService> {
    @Override
    public RemoteProductSkuService create(Throwable cause) {
        log.error("远程服务调用失败", cause.getMessage());
        return new RemoteProductSkuService() {
            //查询首页热门数据的兜底方法
            @Override
            public R<IndexHotData> indexHotData() {
                return R.fail("获取热门数据失败: "+cause.getMessage());
            }

            @Override
            public R<Page<ProductSku>> list(SkuSearchDTO skuSearchDTO) {
                return R.fail("获取商品列表数据失败: " +cause.getMessage());
            }

            @Override
            public R<ProductSkuDTO> getSkuDTOById(Long id) {
                return R.fail("获取商品详情数据失败: " +cause.getMessage());
            }
        };
    }
}
